package com.hxz.service.impl;

import com.hxz.entity.ArticleComment;
import com.hxz.mapper.ArticleCommentMapper;
import com.hxz.service.ArticleCommentService;
import com.hxz.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * Create by Alden He on 2019/5/7
 */
@Service
public class ArticleCommentsServiceImpl implements ArticleCommentService {
	@Autowired
	private ArticleCommentMapper articleCommentMapper;

	/**
	 * 根据文章ID获取文章评论
	 */
	public List<ArticleComment> getArticleCommentsByArticleId(int id) {
		
		return articleCommentMapper.getArticleCommentsByArticleId(id);
	}

	/**
	 * 评论文章
	 */
	public int addArticleComment(ArticleComment articleComment) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar calendar = Calendar.getInstance();
		String dateName = df.format(calendar.getTime());
		articleComment.setCreateTime(dateName);
		return articleCommentMapper.addArticleComment(articleComment);
	}

}
